<template>
	<view class="padding">
		<view v-if="curStep == 1">
			<view class="padding flex flex-direction margin-top"  v-for="(item, index) in categoryList" :key="index">
				<button class="cu-btn bg-blue lg text-bold round " style="height: 100rpx;" @click="nextStep(item)">{{item.label}}</button>
			</view>
		</view>
		
		<view v-if="curStep == 2">
			<view class="cu-list menu card-menu margin-top sm-border" >
				<view class="cu-item arrow"  v-for="(item, index) in categoryChild.children" :key="index" @click="confirmBank(item)">
					<view class="content">
						<text class="text-grey">{{item.label}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { qbmsCategoryList } from '@/api/qbms.js'
	export default {
		data() {
			return {
				categoryList: [], // 分类列表
				categoryChild: {}, // 分类
				curStep: 1, // 当前步骤
				
				pid: 0,
			}
		},
		onLoad(options) {
			if (options.pid) {
				this.pid = options.pid;
			}
			
 		},
		onShow() {
			qbmsCategoryList().then(res => {
				let categoryList = res.data;
				this.categoryList = categoryList;
				if (this.pid) {
					let category = categoryList.find((item) => {
						return item.id = this.pid
					})
					this.curStep = 2;
					this.categoryChild = category
				}
				
			}).catch(err => {});
		},
		methods: {
			
			// 跳转下一步
			nextStep(category) {
				uni.setNavigationBarTitle({
					title: category.label
				})
				this.categoryChild = category;
				this.curStep = 2;
			},
			
			// 确认题库
			confirmBank(category) {
				this.$util.$confirm("是否确认选择该题库？").then(res => {
					uni.setStorageSync("qbankId", category.id);
					let name = this.categoryChild.label + " / " + category.label;
					uni.setStorageSync("qbankName", name);
					uni.switchTab({
						url: "/pages/index/index"
					})
				})
			}
		}
	}
</script>

<style>

</style>
